package com.softtek.base.business.biz.impl;

import com.softtek.base.business.biz.DepartmentInfoBiz;
import com.softtek.base.business.dao.DepartmentInfoDao;
import com.softtek.base.business.dao.QuestionTwoDao;
import com.softtek.base.domain.DepartmentInfo;
import com.softtek.base.domain.QuestionTwo;
import com.softtek.base.domain.VO.DepartmentChannelVO;
import com.softtek.base.domain.VO.RegionVO;
import com.softtek.base.sugar.config.FilePathConfig;
import com.softtek.base.sugar.tools.Configuration;
import com.softtek.base.sugar.web.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015-08-18.
 */

@Service("departmentInfoBiz")
public class DepartmentInfoBizImpl  implements DepartmentInfoBiz {


    private Logger logger = LoggerFactory.getLogger(AdminUserBizImpl.class);

    @Autowired
    private DepartmentInfoDao departmentInfoDao;

    @Autowired
    private QuestionTwoDao questionTwoDao;

    public void groupImage() {
        //根据渠道分类
        List<DepartmentChannelVO> departmentChannelVOList = departmentInfoDao.countChannel();
        //从配置文件获取上传物理根路径
        String fileSaveRootPathFirst = Configuration.getConfigurationByName("fileSaveRootPathFirst");
        if (fileSaveRootPathFirst == null) {
            logger.error("获取文件保存根路径异常。");
        }


        //创建渠道文件夹
        for(DepartmentChannelVO departmentChannelVO : departmentChannelVOList){
            //根路径+上传目录=最终路径
            String companyAbsolutePath = fileSaveRootPathFirst + departmentChannelVO.getDepartmentChannel();
            logger.info("从配置文件获取渠道上传文件路径为[" + companyAbsolutePath + "]");
            logger.info("创建渠道文件夹[" + companyAbsolutePath + "]结果为[" + FileUtils.getFolder(companyAbsolutePath) + "]");
            //根据渠道名称获取到所有的城市
            List<DepartmentInfo> departmentInfoListByChannel = departmentInfoDao.findByType(departmentChannelVO.getDepartmentChannel(),null);
            for (DepartmentInfo departmentInfoByChannel :departmentInfoListByChannel){
                if (!companyAbsolutePath.endsWith("/")) {
                    companyAbsolutePath = companyAbsolutePath + "/";
                }
                String cityPath = companyAbsolutePath + departmentInfoByChannel.getDepartmentCity();
                logger.info("从配置文件获取城市上传文件路径为[" + cityPath + "]");
                logger.info("创建城市文件夹[" + cityPath + "]结果为[" + FileUtils.getFolder(cityPath) + "]");
                //根据渠道名称和城市获取到所有的门店编号
                List<DepartmentInfo> departmentInfoListByChannelAndCity = departmentInfoDao.findByType(departmentChannelVO.getDepartmentChannel(),departmentInfoByChannel.getDepartmentNum());
                    for(DepartmentInfo departmentInfoByChannelAndCity : departmentInfoListByChannelAndCity){
                        if (!cityPath.endsWith("/")) {
                            cityPath = cityPath + "/";
                        }
                        String departmentNumPath = cityPath + departmentInfoByChannelAndCity.getDepartmentNum();
                        logger.info("从配置文件获取城市上传文件路径为[" + departmentNumPath + "]");
                        logger.info("创建门店编号文件夹[" + departmentNumPath + "]结果为[" + FileUtils.getFolder(departmentNumPath) + "]");

                        String fileSaveRootPath = Configuration.getConfigurationByName("fileSaveRootPath");

                        //问题1中的A图片
                         if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneAImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneAImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneA1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneAImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneAImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneA2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneAImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneAImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneA3.jpg");
                        }

                        //问题1中的B图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneBImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneBImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneB1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneBImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneBImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneB2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneBImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneBImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneB3.jpg");
                        }

                        //问题1中的C图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneCImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneCImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneC1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneCImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneCImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneC2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneCImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneCImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneC3.jpg");
                        }

                        //问题1中的D图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneDImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneDImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneD1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneDImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneDImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneD2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneDImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneDImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneD3.jpg");
                        }

                        //问题1中的E图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneEImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneEImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneE1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneEImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneEImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneE2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneEImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneEImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneE3.jpg");
                        }

                        //问题1中的F图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneFImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneFImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneF1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneFImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneFImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneF2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneFImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneFImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneF3.jpg");
                        }

                        //问题1中的G图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneGImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneGImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneG1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneGImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneGImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneG2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneGImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneGImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneG3.jpg");
                        }

                        //问题1中的H图片
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneHImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneHImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneH1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneHImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneHImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneH2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionOneHImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionOneHImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"OneH3.jpg");
                        }

                        //问题2中a选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoA1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoA2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlA3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoA3.jpg");
                        }

                        //问题2中b选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoB1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoB2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlB3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoB3.jpg");
                        }

                        //问题2中C选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoC1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoC2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlC3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoC3.jpg");
                        }
                        //问题2中D选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD())){
                            FileUtils.renameOldFile(fileSaveRootPath + departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD(), departmentNumPath + "/" + departmentInfoByChannelAndCity.getDepartmentInfoId() + "TwoD1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD2())){
                            FileUtils.renameOldFile(fileSaveRootPath + departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoD2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlD3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoD3.jpg");
                        }
                        //问题2中E选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoE1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoE2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlE3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoE3.jpg");
                        }

                        //问题2中G选项图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoG1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoG2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTwoImageUrlG3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"TwoG3.jpg");
                        }

                        //问题3中图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionThreeImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionThreeImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Three1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionThreeImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionThreeImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Three2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionThreeImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionThreeImageUrl3(),departmentNumPath+"/" +departmentInfoByChannelAndCity.getDepartmentInfoId()+"Three3.jpg");
                        }

                        //问题4中图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFourImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFourImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Four1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFourImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFourImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Four2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFourImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFourImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Four3.jpg");
                        }

                        //问题4.1中图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FourSecond1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FourSecond2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FourSecond3.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture4())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionFourOnePicture4(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FourSecond4.jpg");
                        }

                        //问题5中A选项的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlA())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlA(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveA1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlA2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlA2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveA2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlA3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlA3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveA3.jpg");
                        }

                        //问题5中B选项的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlB())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlB(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveB1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlB2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlB2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveB2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlB3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlB3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveB3.jpg");
                        }

                        //问题5中C选项的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlC())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlC(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveC1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlC2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlC2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveC2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionFiveImageUrlC3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionFiveImageUrlC3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"FiveC3.jpg");
                        }

                        //问题6的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSixAnswerImage())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSixAnswerImage(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Six1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSixAnswerImage2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSixAnswerImage2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Six2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSixAnswerImage3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSixAnswerImage3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Six3.jpg");
                        }

                        //问题7的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Seven1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Seven2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionSevenAnswerImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Seven3.jpg");
                        }

                        //问题8的图片
                        if ( StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionEightImageUrlA())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionEightImageUrlA(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eight1.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionEightImageUrlB())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionEightImageUrlB(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eight2.jpg");
                        }
                        if (StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionEightImageUrlC())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionEightImageUrlC(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eight3.jpg");
                        }

                        //问题10的图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Ten1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Ten2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionTenAnswerImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Ten3.jpg");
                        }

                        //问题11的图片
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eleven1.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl2())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl2(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eleven2.jpg");
                        }
                        if (departmentInfoByChannelAndCity.getQuestionTwo()!=null && StringUtils.isNotBlank(departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl3())){
                            FileUtils.renameOldFile(fileSaveRootPath+departmentInfoByChannelAndCity.getQuestionTwo().getQuestionElevenAnswerImageUrl3(),departmentNumPath+"/"+departmentInfoByChannelAndCity.getDepartmentInfoId()+"Eleven3.jpg");
                        }
                    }
            }
        }
        logger.info("全部创建成果");
    }

    @Override
    public List<DepartmentInfo> findByKaSr(String type,String departmentChannel) {
        return departmentInfoDao.findByKaSr(type,departmentChannel);
    }

    @Override
    public int countByKaSrAndCanUserDepartment(String departmentChannel) {
        return departmentInfoDao.countByKaSrAndCanUserDepartment(departmentChannel);
    }

    @Override
    public int countQuestionOneAnswer(String type, String departmentChannel) {
        return departmentInfoDao.countQuestionOneAnswer(type,departmentChannel);
    }

    @Override
    public int countQuestionSevenAnswer(String departmentChannel) {
        return departmentInfoDao.countQuestionSevenAnswer(departmentChannel);
    }

    @Override
    public int countQuestionTwoAnswer(String departmentChannel) {
        return departmentInfoDao.countQuestionTwoAnswer(departmentChannel);
    }

    @Override
    public int countQuestionFiveAnswer(String questionFiveAnswerA, String questionFiveAnswerB, String departmentChannel) {
        return departmentInfoDao.countQuestionFiveAnswer(questionFiveAnswerA,questionFiveAnswerB,departmentChannel);
    }

    @Override
    public int countQuestionEightAnswer(String type, String departmentChannel) {
        return departmentInfoDao.countQuestionEightAnswer(type,departmentChannel);
    }

    @Override
    public int countQuestionTwoAnswer(String type, String departmentChannel) {
        return departmentInfoDao.countQuestionTwoAnswer(type,departmentChannel);
    }

    @Override
    public List<RegionVO> countKaSr() {
        return departmentInfoDao.countKaSr();
    }

    @Override
    public int countEdit() {
        return departmentInfoDao.countEdit();
    }

    @Override
    public List<DepartmentInfo> findByType(Integer pageNow, Integer pageSize, String departmentName, String departmentNum, String status) {
        return departmentInfoDao.findByType(pageNow,pageSize,departmentName,departmentNum,status);
    }

    @Override
    public int count(String departmentName, String departmentNum, String status) {
        return departmentInfoDao.count(departmentName,departmentNum,status);
    }

    @Override
    public Long totalRecord() {
        return this.totalRecord(null);
    }

    @Override
    public Long totalRecord(Map<String, String> queryHash) {
        return departmentInfoDao.totalRecord(queryHash);
    }

    @Override
    public List<DepartmentInfo> findList() {
        return this.findList(0, 0, null);
    }

    @Override
    public List<DepartmentInfo> findList(Map<String, String> queryHash) {
        return this.findList(0, 0, queryHash);
    }

    @Override
    public List<DepartmentInfo> findList(Integer pageNow, Integer pageSize) {
        return this.findList(pageNow, pageSize, null);
    }

    @Override
    public List<DepartmentInfo> findList(Integer pageNow, Integer pageSize, Map<String, String> queryHash) {
        return this.findList(pageNow, pageSize, "", queryHash);
    }

    @Override
    public List<DepartmentInfo> findList(Integer pageNow, Integer pageSize, String sqlOrder, Map<String, String> queryHash) {
        return departmentInfoDao.findList(pageNow, pageSize, sqlOrder, queryHash);
    }

    @Override
    public DepartmentInfo findModel(Long departmentInfoId) {
        return departmentInfoDao.findModel(departmentInfoId);
    }

    @Override
    @Transactional
    public void addOrUpdate(DepartmentInfo model) {
        if (model.getDepartmentInfoId() != null && model.getDepartmentInfoId() > 0) {
            logger.info("当前需修改的DepartmentInfo对象departmentInfoId为[" + model.getDepartmentInfoId() + "]");
            departmentInfoDao.update(model);
        } else {
            logger.info("DepartmentInfoBizImpl添加departmentInfo！");
            departmentInfoDao.add(model);
        }
    }

    @Override
    @Transactional
    public void addOrUpdate(DepartmentInfo model,
                            QuestionTwo questionTwo,
                            String fileNameQuestionTwoAImageUrl1,
                            String fileNameQuestionTwoAImageUrl2,
                            String fileNameQuestionTwoAImageUrl3,
                            String fileNameQuestionTwoBImageUrl1,
                            String fileNameQuestionTwoBImageUrl2,
                            String fileNameQuestionTwoBImageUrl3,
                            String fileNameQuestionTwoCImageUrl1,
                            String fileNameQuestionTwoCImageUrl2,
                            String fileNameQuestionTwoCImageUrl3,
                            String fileNameQuestionTwoDImageUrl1,
                            String fileNameQuestionTwoDImageUrl2,
                            String fileNameQuestionTwoDImageUrl3,
                            String fileNameQuestionTwoEImageUrl1,
                            String fileNameQuestionTwoEImageUrl2,
                            String fileNameQuestionTwoEImageUrl3,
                            String fileNameQuestionTwoGImageUrl1,
                            String fileNameQuestionTwoGImageUrl2,
                            String fileNameQuestionTwoGImageUrl3,
                            String fileNameQuestionTenImageUrl1,
                            String fileNameQuestionTenImageUrl2,
                            String fileNameQuestionTenImageUrl3,
                            String fileNameQuestionElevenImageUrl1,
                            String fileNameQuestionElevenImageUrl2,
                            String fileNameQuestionElevenImageUrl3) {
        if (questionTwo==null || questionTwo.getQuestionTwoId()==null){
            if (StringUtils.isNotBlank(model.getQuestionFourAnswer()) && model.getQuestionFourAnswer().equals("2")){
                questionTwo.setQuestionFourOneAnswerA("2");
                questionTwo.setQuestionFourOneAnswerB("2");
                questionTwo.setQuestionFourOneAnswerC("2");
                questionTwo.setQuestionFourOneAnswerD("2");
                questionTwo.setQuestionFourOneAnswerANum("");
                questionTwo.setQuestionFourOneAnswerBNum("");
            }
            questionTwoDao.add(questionTwo);
        }
        else {
            questionTwoDao.update(questionTwo,model.getQuestionFourAnswer());
        }
        logger.info("QuestionTwoId:"+questionTwo.getQuestionTwoId());
        model.setQuestionTwo(questionTwo);
        if (model.getDepartmentInfoId() != null && model.getDepartmentInfoId() > 0) {
            logger.info("当前需修改的DepartmentInfo对象departmentInfoId为[" + model.getDepartmentInfoId() + "]");
            departmentInfoDao.update(model);
        } else {
            logger.info("DepartmentInfoBizImpl添加departmentInfo！");
            departmentInfoDao.add(model);
        }
    }

}
